<!DOCTYPE html>
<html>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  

  
  <title>2018级计科1、计科2、网工、信安班第14周竞赛题 | Tootal World</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="前言本文中的题目做法仅供参考，不一定是最简单或是最正确的方法。每题附的程序源码均在当时通过了OJ测试，但随着时间的推移也有可能失效。作者水平有限，如有疏漏，在所难免，望留言指出。 AProblem A: Balloon Comes!分情况处理，除法时注意判断一下能否整除即可。">
<meta name="keywords" content="C++">
<meta property="og:type" content="article">
<meta property="og:title" content="2018级计科1、计科2、网工、信安班第14周竞赛题">
<meta property="og:url" content="http://tootal.xyz/2018/12/03/2018级计科1、计科2、网工、信安班第14周竞赛题/index.html">
<meta property="og:site_name" content="Tootal World">
<meta property="og:description" content="前言本文中的题目做法仅供参考，不一定是最简单或是最正确的方法。每题附的程序源码均在当时通过了OJ测试，但随着时间的推移也有可能失效。作者水平有限，如有疏漏，在所难免，望留言指出。 AProblem A: Balloon Comes!分情况处理，除法时注意判断一下能否整除即可。">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2018-12-12T14:20:58.143Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="2018级计科1、计科2、网工、信安班第14周竞赛题">
<meta name="twitter:description" content="前言本文中的题目做法仅供参考，不一定是最简单或是最正确的方法。每题附的程序源码均在当时通过了OJ测试，但随着时间的推移也有可能失效。作者水平有限，如有疏漏，在所难免，望留言指出。 AProblem A: Balloon Comes!分情况处理，除法时注意判断一下能否整除即可。">
  
    <link rel="alternate" href="../../../../atom.xml" title="Tootal World" type="application/atom+xml">
  
  
    <link rel="icon" href="http://tootal.xyz/favicon.png">
  
  
    <link href="http://fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="../../../../css/style.css">
</head>
</html>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="../../../../index.html" id="logo">Tootal World</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="../../../../index.html" id="subtitle">在时光的流逝中，逐渐成为更好的自己。</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="../../../../index.html">Home</a>
        
          <a class="main-nav-link" href="../../../../archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="../../../../atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
		<!--below use google search-->
        <!--%- search_form({button: '&#xF002;'}) %-->
		<!--below use baidu search-->
		 <!--form action="http://www.baidu.com/baidu" method="get" accept-charset="utf-8" class="search-form">
          <input type="search" name="word" maxlength="20" class="search-form-input" placeholder="Search">
          <input type="submit" value="" class="search-form-submit">
          <input name=tn type=hidden value="bds">
          <input name=cl type=hidden value="3">
          <input name=ct type=hidden value="2097152">
          <input type="hidden" name="si" value="tootal.xyz">
        </form-->
		<!--below use swiftype search-->
		<!--input type="search" name="word" maxlength="20" class="st-default-search-input" placeholder="Search"-->
		<input type="text" class="st-default-search-input">
		<script type="text/javascript">
			(function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
			(w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);
			e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
			})(window,document,'script','//s.swiftypecdn.com/install/v2/st.js','_st');
			_st('install','PwDt_XJKCzu2LMzrR5qV','2.0.0');
		</script>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-2018级计科1、计科2、网工、信安班第14周竞赛题" class="article article-type-post" itemscope="" itemprop="blogPost">
  <div class="article-meta">
    <a href="index.html" class="article-date">
  <time datetime="2018-12-03T09:09:42.000Z" itemprop="datePublished">2018-12-03</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      2018级计科1、计科2、网工、信安班第14周竞赛题
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h1 id="前言"><a href="index.html#前言" class="headerlink" title="前言"></a>前言</h1><p>本文中的题目做法仅供参考，不一定是最简单或是最正确的方法。<br>每题附的程序源码均在当时通过了OJ测试，但随着时间的推移也有可能失效。<br>作者水平有限，如有疏漏，在所难免，望留言指出。</p>
<h1 id="A"><a href="index.html#A" class="headerlink" title="A"></a>A</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1732&amp;pid=0" target="_blank" rel="noopener">Problem A: Balloon Comes!</a><br>分情况处理，除法时注意判断一下能否整除即可。<br><a id="more"></a><br><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iomanip&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> t;</span><br><span class="line">	<span class="built_in">cin</span>&gt;&gt;t;</span><br><span class="line">	<span class="keyword">while</span>(t--)&#123;</span><br><span class="line">		<span class="keyword">char</span> c;</span><br><span class="line">		<span class="keyword">int</span> a,b;</span><br><span class="line">		<span class="built_in">cin</span>&gt;&gt;c&gt;&gt;a&gt;&gt;b;</span><br><span class="line">		<span class="keyword">if</span>(c==<span class="string">'+'</span>)<span class="built_in">cout</span>&lt;&lt;a+b&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(c==<span class="string">'-'</span>)<span class="built_in">cout</span>&lt;&lt;a-b&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(c==<span class="string">'*'</span>)<span class="built_in">cout</span>&lt;&lt;a*b&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="keyword">else</span> <span class="keyword">if</span>(c==<span class="string">'/'</span>)&#123;</span><br><span class="line">			<span class="keyword">if</span>(a%b==<span class="number">0</span>)&#123;</span><br><span class="line">				<span class="built_in">cout</span>&lt;&lt;a/b&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">			&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">				<span class="built_in">cout</span>&lt;&lt;fixed&lt;&lt;setprecision(<span class="number">2</span>)&lt;&lt;<span class="keyword">double</span>(a)/b&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<h1 id="B"><a href="index.html#B" class="headerlink" title="B"></a>B</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1732&amp;pid=1" target="_blank" rel="noopener">Problem B: 整数翻转</a><br>主要在于如何判断溢出，这里采用了开long long类型的变量，通过比较大小判断是否溢出。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> N=<span class="number">2147483647</span>;</span><br><span class="line"><span class="function"><span class="keyword">long</span> <span class="keyword">long</span> <span class="title">rev</span><span class="params">(<span class="keyword">long</span> <span class="keyword">long</span> x)</span></span>&#123;</span><br><span class="line">	<span class="keyword">long</span> <span class="keyword">long</span> ans=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">while</span>(x)&#123;</span><br><span class="line">		ans=ans*<span class="number">10</span>+x%<span class="number">10</span>;</span><br><span class="line">		x/=<span class="number">10</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> ans;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">long</span> <span class="keyword">long</span> n;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;n)&#123;</span><br><span class="line">		<span class="keyword">long</span> <span class="keyword">long</span> re=rev(n);</span><br><span class="line">		<span class="keyword">if</span>(re&gt;=(-N<span class="number">-1</span>)&amp;&amp;re&lt;=N)<span class="built_in">cout</span>&lt;&lt;re&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">		<span class="keyword">else</span> <span class="built_in">cout</span>&lt;&lt;<span class="string">"0\n"</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="C"><a href="index.html#C" class="headerlink" title="C"></a>C</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1732&amp;pid=2" target="_blank" rel="noopener">Problem C: 各位相加</a><br>按照题意模拟，把各个位上的数加起来，递归处理。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">dig</span><span class="params">(<span class="keyword">int</span> x)</span></span>&#123;</span><br><span class="line">	<span class="keyword">if</span>(x&lt;<span class="number">10</span>)<span class="keyword">return</span> x;</span><br><span class="line">	<span class="keyword">int</span> sum=<span class="number">0</span>;</span><br><span class="line">	<span class="keyword">while</span>(x)&#123;</span><br><span class="line">		sum+=x%<span class="number">10</span>;</span><br><span class="line">		x/=<span class="number">10</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> dig(sum);</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> n;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;n)&#123;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;dig(n)&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="D"><a href="index.html#D" class="headerlink" title="D"></a>D</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1732&amp;pid=3" target="_blank" rel="noopener">Problem D: 整数转化为罗马数字</a><br>罗马数字看似复杂其实也有规律可循。<br>与普通数字一样可以按位处理。这里采用了常量字符串数组简化判断过程。<br>s[1]~s[9]对应罗马数字的1~9<br>s[11]~s[19]对应罗马数字的10~90<br>后面的以此类推。<br>注意0是没有对应的罗马数字的。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="built_in">string</span> s[]=&#123;<span class="string">"0"</span>,<span class="string">"I"</span>,<span class="string">"II"</span>,<span class="string">"III"</span>,<span class="string">"IV"</span>,<span class="string">"V"</span>,<span class="string">"VI"</span>,<span class="string">"VII"</span>,<span class="string">"VIII"</span>,<span class="string">"IX"</span>,<span class="string">"0"</span>,<span class="string">"X"</span>,<span class="string">"XX"</span>,<span class="string">"XXX"</span>,<span class="string">"XL"</span>,<span class="string">"L"</span>,<span class="string">"LX"</span>,<span class="string">"LXX"</span>,<span class="string">"LXXX"</span>,<span class="string">"XC"</span>,<span class="string">"0"</span>,<span class="string">"C"</span>,<span class="string">"CC"</span>,<span class="string">"CCC"</span>,<span class="string">"CD"</span>,<span class="string">"D"</span>,<span class="string">"DC"</span>,<span class="string">"DCC"</span>,<span class="string">"DCCC"</span>,<span class="string">"CM"</span>,<span class="string">"0"</span>,<span class="string">"M"</span>,<span class="string">"MM"</span>,<span class="string">"MMM"</span>&#125;;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="built_in">string</span> ss;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;ss)&#123;</span><br><span class="line">		<span class="keyword">int</span> len=ss.length();</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;len;i++)&#123;</span><br><span class="line">			<span class="keyword">if</span>(ss[i]!=<span class="string">'0'</span>)<span class="built_in">cout</span>&lt;&lt;s[(len-i<span class="number">-1</span>)*<span class="number">10</span>+ss[i]-<span class="string">'0'</span>];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="E"><a href="index.html#E" class="headerlink" title="E"></a>E</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1732&amp;pid=4" target="_blank" rel="noopener">Problem E: 旋转数组</a></p>
<p>显然移动k次和移动k%n次是一样的。<br>其实也不必真的移动数组中的元素，改变一下输出的顺序就行。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> n;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;n)&#123;</span><br><span class="line">		<span class="keyword">if</span>(n==<span class="number">0</span>)<span class="keyword">break</span>;</span><br><span class="line">		<span class="keyword">int</span> a[<span class="number">55</span>];</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)&#123;</span><br><span class="line">			<span class="built_in">cin</span>&gt;&gt;a[i];</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="keyword">int</span> k;</span><br><span class="line">		<span class="built_in">cin</span>&gt;&gt;k;</span><br><span class="line">		k%=n;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=n-k+<span class="number">1</span>;i&lt;=n;i++)</span><br><span class="line">			<span class="built_in">cout</span>&lt;&lt;a[i]&lt;&lt;<span class="string">' '</span>;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n-k;i++)&#123;</span><br><span class="line">			<span class="built_in">cout</span>&lt;&lt;a[i];</span><br><span class="line">			<span class="keyword">if</span>(i==n-k)<span class="built_in">cout</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">			<span class="keyword">else</span> <span class="built_in">cout</span>&lt;&lt;<span class="string">' '</span>;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="F"><a href="index.html#F" class="headerlink" title="F"></a>F</h1><p><a href="http://222.201.146.216/JudgeOnline/problem.php?cid=1732&amp;pid=5" target="_blank" rel="noopener">Problem F: Zigzag表示</a><br>此题可以找规律发现输出字符串下标的关系。<br>具体过程就不在此细说了。<br>注意运算过程中下标不要越界了。<br>下面程序在字符串末尾添加了大量空格，避免了特殊处理越界情况。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;string&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="built_in">string</span> s;</span><br><span class="line">	<span class="keyword">int</span> n;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;s&gt;&gt;n)&#123;</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i&lt;<span class="number">1000</span>;i++)s+=<span class="string">" "</span>;</span><br><span class="line">		<span class="keyword">int</span> len=s.length();</span><br><span class="line">		<span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i&lt;=n;i++)&#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="keyword">int</span> j=i<span class="number">-1</span>;j&lt;len;j+=(n<span class="number">-1</span>)*<span class="number">2</span>)&#123;</span><br><span class="line">				<span class="keyword">if</span>(s[j-(i<span class="number">-1</span>)*<span class="number">2</span>]!=<span class="string">' '</span>&amp;&amp;i!=n&amp;&amp;j-(i<span class="number">-1</span>)*<span class="number">2</span>&gt;=n&amp;&amp;j-(i<span class="number">-1</span>)*<span class="number">2</span>!=j)<span class="built_in">cout</span>&lt;&lt;s[j-(i<span class="number">-1</span>)*<span class="number">2</span>];</span><br><span class="line">				<span class="keyword">if</span>(s[j]!=<span class="string">' '</span>)<span class="built_in">cout</span>&lt;&lt;s[j];</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		<span class="built_in">cout</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="C-1"><a href="index.html#C-1" class="headerlink" title="C+"></a>C+</h1><p>这里给出C题另外一种做法，巧妙的利用了求余与数位的性质。<br>在此就不给出推导过程与证明了。</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;iostream&gt;</span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">	<span class="keyword">int</span> n;</span><br><span class="line">	<span class="keyword">while</span>(<span class="built_in">cin</span>&gt;&gt;n)&#123;</span><br><span class="line">		<span class="keyword">if</span>(n==<span class="number">0</span>)<span class="built_in">cout</span>&lt;&lt;<span class="string">"0\n"</span>;</span><br><span class="line">		<span class="keyword">else</span> <span class="built_in">cout</span>&lt;&lt;(n+<span class="number">8</span>)%<span class="number">9</span>+<span class="number">1</span>&lt;&lt;<span class="built_in">endl</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://tootal.xyz/2018/12/03/2018级计科1、计科2、网工、信安班第14周竞赛题/" data-id="cjpqil6j900053gtkg9b86tap" class="article-share-link">Share</a>
      
      
        <a href="index.html#comments" class="article-comment-link">
          <span class="post-comments-count valine-comment-count" data-xid="/2018/12/03/2018级计科1、计科2、网工、信安班第14周竞赛题/" itemprop="commentCount"></span>
          Comments
        </a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="../../../../tags/C/index.html">C++</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="../../06/2018级-C-第5章课后作业-计科1班、创新班、辅修班/index.html" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          2018级-C++-第5章课后作业(计科1班、创新班、辅修班)
        
      </div>
    </a>
  
  
    <a href="../../02/2018-年计算机科学与工程学院新生赛-2/index.html" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">2018 年计算机科学与工程学院新生赛 #2</div>
    </a>
  
</nav>

  
</article>



  <section id="comments" class="vcomment">

  </section>
</section>
        
          <aside id="sidebar">
  
    

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/ACM/index.html">ACM</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/C/index.html">C++</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Math/index.html">Math</a></li><li class="tag-list-item"><a class="tag-list-link" href="../../../../tags/Minecraft/index.html">Minecraft</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="../../../../tags/ACM/index.html" style="font-size: 20px;">ACM</a> <a href="../../../../tags/C/index.html" style="font-size: 20px;">C++</a> <a href="../../../../tags/Math/index.html" style="font-size: 15px;">Math</a> <a href="../../../../tags/Minecraft/index.html" style="font-size: 10px;">Minecraft</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="http://tootal.xyz/archives/2018/12/">December 2018</a></li><li class="archive-list-item"><a class="archive-list-link" href="http://tootal.xyz/archives/2018/11/">November 2018</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="../../21/Net-Cloud-Music&#32;List&#32;Download/index.html">Net-Cloud-Music List Download</a>
          </li>
        
          <li>
            <a href="../../21/三角函数和差化积、积化和差公式推导记忆/index.html">三角函数和差化积、积化和差公式推导记忆</a>
          </li>
        
          <li>
            <a href="../../17/《高级语言程序设计C++（一）》样卷/index.html">《高级语言程序设计C++（一）》样卷</a>
          </li>
        
          <li>
            <a href="../../14/Minecraft-Server-Tootal-World/index.html">Minecraft Server Tootal World</a>
          </li>
        
          <li>
            <a href="../../10/2018级计科1、计科2、网工、信安班第15周竞赛题/index.html">2018级计科1、计科2、网工、信安班第15周竞赛题</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2018 tootal<br>
      Powered by <a href="https://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="../../../../index.html" class="mobile-nav-link">Home</a>
  
    <a href="../../../../archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="../../../../fancybox/jquery.fancybox.css">
  <script src="../../../../fancybox/jquery.fancybox.pack.js"></script>


<script src="../../../../js/script.js"></script>




  <script src="http://cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="http://unpkg.com/valine/dist/Valine.min.js"></script>
<script>
    var GUEST_INFO = ['nick','mail','link'];
    var guest_info = 'nick,mail,link'.split(',').filter(function(item){
        return GUEST_INFO.indexOf(item) > -1
    });
    var notify = 'false' == true;
    var verify = 'false' == true;
    new Valine({
        el: '.vcomment',
        notify: notify,
        verify: verify,
        appId: "M3v8N5hOEvMyXAbssqMm35dx-gzGzoHsz",
        appKey: "cPadTqnA1Me5mlv0N4Ix96Xl",
        placeholder: "Please leave your footprints.",
        pageSize:'10',
        avatar:'mm',
        lang:'zh-cn'
    });
</script>

  </div>
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<!--script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"></script>

</body>
</html>